using System;
using System.Collections.Generic;
using System.Text;

using System.Xml;

namespace Horizon
{
    /// <summary>
    /// Exception type to wrap errors returned in Horizon XML data
    /// </summary>
    public class HorizonError : Exception
    {
        private string _severity, _className, _methodName, _detail, _exception;

        /// <summary>
        /// Creates a HorizonError object given an Error node
        /// </summary>
        /// <param name="errorNode"></param>
        public HorizonError(XmlNode errorNode) : base(HorizonDataAccess.SafeInnerText(errorNode.SelectSingleNode("//message")))
        {
            _severity = HorizonDataAccess.SafeInnerText(errorNode.SelectSingleNode("//severity"));
            _className = HorizonDataAccess.SafeInnerText(errorNode.SelectSingleNode("//classname"));
            _methodName = HorizonDataAccess.SafeInnerText(errorNode.SelectSingleNode("//methodname")); 
            _detail = HorizonDataAccess.SafeInnerText(errorNode.SelectSingleNode("//detail"));
            _exception = HorizonDataAccess.SafeInnerText(errorNode.SelectSingleNode("//exception"));
        }

        /// <summary>
        /// Data returned in the exception XML element
        /// </summary>
        public string ExceptionInfo
        {
            get { return _exception; }
            set { _exception = value; }
        }

        /// <summary>
        /// Data returned in the detail XML element
        /// </summary>
        public string Detail
        {
            get { return _detail; }
            set { _detail = value; }
        }

        /// <summary>
        /// Data returned in the methodname XML element
        /// </summary>
        public string MethodName
        {
            get { return _methodName; }
            set { _methodName = value; }
        }

        /// <summary>
        /// Data returned in the classname XML element
        /// </summary>
        public string ClassName
        {
            get { return _className; }
            set { _className = value; }
        }

        /// <summary>
        /// Data returned in the severity XML element
        /// </summary>
        public string Severity
        {
            get { return _severity; }
            set { _severity = value; }
        }
    }
}
